// CopyDialog.cpp

#include "StdAfx.h"

#include "Common/FileSystem/FileName.h"

#include "CopyDialog.h"

#ifdef LANG
#include "Common/Lang/LangUtils.h"
#endif

using namespace Common;

#ifdef LANG
static Lang::CIDLangPair kIDLangPairs[] =
{
  { IDOK, 0x02000702 },
  { IDCANCEL, 0x02000710 }
};
#endif

LRESULT CCopyDialog::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
  #ifdef LANG
  Lang::LangSetDlgItemsText(HWND(*this), kIDLangPairs, sizeof(kIDLangPairs) / sizeof(kIDLangPairs[0]));
  #endif
  _path.Attach(GetDlgItem(IDC_COPY_COMBO));
  SetWindowText(Title);

  CStatic staticContol;
  staticContol.Attach(GetDlgItem(IDC_COPY_STATIC));
  staticContol.SetWindowText(Static);
  #ifdef UNDER_CE
  // we do it, since WinCE selects Value\something instead of Value !!!!
  _path.AddString(Value);
  #endif
  for (size_t i = 0; i < Strings.size(); i++)
    _path.AddString(Strings[i]);
  _path.SetWindowText(Value);
  GetDlgItem(IDC_COPY_INFO).SetWindowText(Info);
   CenterWindow(GetParent());
   return TRUE;
}

LRESULT CCopyDialog::OnSize(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/)
{
	int xSize = LOWORD(lParam);
	int ySize = HIWORD(lParam);
  int mx, my;
  RECT rect;
    rect.left = 0;
    rect.top = 0;
    rect.right = 8;
    rect.bottom = 8;
    MapDialogRect(&rect);
	mx = rect.right - rect.left;
    my = rect.bottom - rect.top;
  
	int bx1, bx2, by;
  CWindow wndCancel = GetDlgItem(IDCANCEL);
  wndCancel.GetWindowRect(&rect);
  bx1 = rect.right - rect.left;
  by = rect.bottom - rect.top;
  CWindow wndOK = GetDlgItem(IDOK);
  wndOK.GetWindowRect(&rect);
  bx2 = rect.right - rect.left;
  int y = ySize - my - by;
  int x = xSize - mx - bx1;

  InvalidateRect(NULL);
  CWindow wndPath;
  {
    //RECT rect;
	wndPath = GetDlgItem(IDC_COPY_SET_PATH);
	wndPath.GetClientRect(&rect);
    int bx = rect.right - rect.left;
	wndPath.MoveWindow( xSize - mx - bx, rect.top, bx, rect.bottom - rect.top);
    ChangeSubWindowSizeX(_path, xSize - mx - mx - bx - mx, m_hWnd);
  }

  {
	  RECT rect ={0};
	wndPath = GetDlgItem(IDC_COPY_INFO);
    int yPos = rect.top;
    wndPath.MoveWindow(mx, yPos, xSize - mx * 2, y - 2 - yPos);
  }

  wndCancel.MoveWindow(x, y, bx1, by);
  wndOK.MoveWindow(x - mx - bx2, y, bx2, by);

 return 0L;
}


LRESULT CCopyDialog::OnButtonSetPath(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
  CString currentPath;
  _path.GetWindowText(currentPath);

  CString title = Lang::LangStringSpec(IDS_SET_FOLDER, 0x03020209);

 

  CFolderDialog dlg(*this, title, BIF_RETURNONLYFSDIRS|BIF_NEWDIALOGSTYLE| BIF_STATUSTEXT);
  if(!currentPath.IsEmpty())
	  dlg.SetInitialFolder(currentPath);
  if (IDOK == dlg.DoModal())
  {
	CString resultPath (dlg.GetFolderPath());  
	FileSystem::FileName::NormalizeDirPathPrefix(resultPath);
	_path.SetCurSel(-1);
	_path.SetWindowText(resultPath);
  }

  return 1L;
}

 LRESULT CCopyDialog::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
  _path.GetWindowText(Value);
  EndDialog(wID);
	return 0;
}
